from flask_restful import Resource

from model.crud import QueryOneInstance, DeleteInstance
from model.tables import Blog
from restful.data import DataPid
from restful.error import RenderPostNotExist
from restful.response import ResponseSuccess
from restful.session import current_user_required,data


class PostDelete(Resource):
    @current_user_required
    @data(DataPid())
    def delete(self,data,current_user):
        blog = QueryOneInstance(Blog,{'uid':current_user.id,'id':data['pid']})
        if not blog :
            return RenderPostNotExist(data['pid'])

        DeleteInstance(blog)
        return ResponseSuccess(msg="删除成功")